1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
---
import { type CollectionEntry, getCollection } from "astro:content";
import Base from "@layouts/Base.astro";
import BlogCard from "@components/BlogCard.astro";
import SimplePostList from "@components/templates/SimplePostList.astro";
type Props = { posts: CollectionEntry<"blog">[] };
export async function getStaticPaths() {
const posts = await getCollection("blog");
const keywords = [
...new Set(
await getCollection("blog").then((x) =>
x.flatMap((x) => x.data.keywords)
),
).values(),
];
return keywords.map((k) => ({
params: { keyword: k },
props: {
posts: posts.filter((post) =>
post.data.keywords.some((i) => i.localeCompare(k) === 0)
),
},
}));
}
const title = `Blogue &ndash ${Astro.params.keyword}`;
const description = `Últimas postagens da categoria ${Astro.params.keyword}.`;
const posts = Astro.props.posts.sort((a, b) =>
new Date(b.data.dateCreated).valueOf() -
new Date(a.data.dateCreated).valueOf()
);
---
<Base {title} {description}>
<main
itemprop="mainContentOfPage"
itemscope
itemtype="https://schema.org/WebPageElement"
>
<section
id="posts"
itemprop="citation"
itemscope
itemtype="http://schema.org/Blog"
>
<h2 itemprop="name description" set:html={title} />
<SimplePostList
{posts}
dateOptions={{
weekday: "long",
year: "numeric",
month: "long",
day: "numeric",
hour: "2-digit",
minute: "2-digit",
timeZoneName: "long",
}}
/>
</section>
</main>
</Base>
|